﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using SFA;
using System.Configuration;

public partial class CandidateDetail : System.Web.UI.Page
{


    public string CVPath = ConfigurationSettings.AppSettings["CvPath"];
    public string DocumentPath = ConfigurationSettings.AppSettings["ProfilePic"];


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {


            GetCandidateDetailsDataSet(CommonUtility.GetLoggedOnUserId());
            //GetCandidatePaymentDetails(cid);
            mvwCandidateReg.ActiveViewIndex = 0;
            mainMenu_MenuItemClick(sender, null);
        }

    }

    public void GetCandidateData(DataTable DtCandidateData)
    {
        tdAccreditationType.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["AccrediationType"]);
        // tdCandidateType.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CandidateType"]);
        string strCandidateType = Convert.ToString(DtCandidateData.Rows[0]["CandidateType"]);
        tdCandidateType.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CandidateType"]);
        if (strCandidateType == "Independent")
        {
            trMarketReserachCompany.Visible = false;
        }
        else
        {
            trMarketReserachCompany.Visible = true;
            tdMarketReserachCompany.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CompanyName"]);
        }
        // tdCompanyName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CompanyName"]);
        tdEmail.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Email"]);
        tdRegistrationNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["RegistrationNo"]);
        
        tdFirstName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["FirstName"]);
        string middlename = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);
        if (middlename == "")
        {
            tdMiddleName.InnerHtml = "&nbsp;&nbsp;-";

        }
        else
        {
            tdMiddleName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);

        }
        tdLastName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["LastName"]);
        //string strDOB = Convert.ToString(DtCandidateData.Rows[0]["DOB"]);
        //string dateOnlyString = strDOB.ToShortDateString();
        tdDOB.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["conDOB"]);
        string strGender = Convert.ToString(DtCandidateData.Rows[0]["Gender"]);
        //if (strGender == "M")
        //{
        //    tdGender.InnerHtml = "Male";
        //}
        //else
        //{
        //    tdGender.InnerHtml = "Female";
        //}
        //tdGender.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Gender"]);
        //tdNationalityID.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["NationalityID"]);
        tdNationality.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["NationalityName"]);
        tdContectAddress.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ContactAddress"]);
        tdCountry.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CountryName"]);
        tdState.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["StateName"]);
        tdZipCode.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ZipCode"]);

        //tdHomePhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["OtherPhoneNo"]);
        string otherphoneno = Convert.ToString(DtCandidateData.Rows[0]["OtherPhoneNo"]);
        string[] otherphonenoparts = otherphoneno.Split('-');
        if (otherphonenoparts[0] == "" || otherphonenoparts[1] == "" || otherphonenoparts[2] == "")
        { tdHomePhoneNo.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
            tdHomePhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["OtherPhoneNo"]);

        }

        // tdWorkPhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);

        string phoneno = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);
        string[] phonenoparts = phoneno.Split('-');
        if (phonenoparts[0] == "" || phonenoparts[1] == "" || phonenoparts[2] == "")
        { tdWorkPhoneNo.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
            tdWorkPhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);

        }


        // tdMobileNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);
        string mobileno = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);
        string[] mobparts = mobileno.Split('-');
        if (mobparts[1] == "")
        { tdMobileNo.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
            tdMobileNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);

        }

        //tdGraduationID.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["GraduationID"]);
        tdGraduation.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["GraduationType"]);
        //tdSpecialization.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Specialisation"]);
        tdSpecialization.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Specialisation"]);
        tdUniversity.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["University"]);
        //tdQualificationStatusID.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["QualificationStatusID"]);
        tdStatus.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["QualificationStatus"]);
        //tdCompanyName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CompanyName"]);
        //txtStatusID.Text = Convert.ToString(DtCandidateData.Rows[0]["StatusID"]);

        tdProCurrentRole.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProCurrentRole"]);
        tdProExperience.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProExperience"]);
        tdProfQualitative1.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative1"]);
        tdProfQualitative2.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative2"]);
        tdProfQualitative3.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative3"]);
        tdProfQualitative4.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative4"]);


        string strProfilePath = Convert.ToString(DtCandidateData.Rows[0]["ProfilePicturePath"]);
        if (strProfilePath == "")
        {
            Image1.ImageUrl = "~/Images/Unknown2.jpg";
        }
        else
        {
            Image1.ImageUrl = DocumentPath + '/' + strProfilePath;
        }
        tdCandidateLanguageDetail.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["LanguageList"]);
        txtStatusID.Text = Convert.ToString(DtCandidateData.Rows[0]["StatusID"]);

        string strPath = string.Empty;
        string strCvTitle = Convert.ToString(DtCandidateData.Rows[0]["CVPath"]);
        //string strAuthority = HttpContext.Current.Request.Url.Authority;
        string strAuthority = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;

        string strUCvpath = CVPath.Remove(0, 1);

        strPath = strAuthority + strUCvpath + strCvTitle;

        tdUploadResume.InnerHtml = "<a href=javascript:onClickLink('" + strPath + "')>" + "<b>Click Here</b>" + "</a>";
    }


    public void GetUserPaymentDetails(DataTable DtGetUserPaymentDetailsData)
    {
        tdCandidateID.InnerHtml = Convert.ToString(DtGetUserPaymentDetailsData.Rows[0]["CandidateID"]);
        tdPaymentAmount.InnerHtml = Convert.ToString(DtGetUserPaymentDetailsData.Rows[0]["PaymentAmount"]);
        tdPaymentDate.InnerHtml = Convert.ToString(DtGetUserPaymentDetailsData.Rows[0]["PaymentDate"]);
        string txnId = Convert.ToString(DtGetUserPaymentDetailsData.Rows[0]["TxnId"]);
        if (txnId == "")
        {
            trTxnID.Visible = false;
        }
        else
        {
            tdTxnId.InnerHtml = Convert.ToString(DtGetUserPaymentDetailsData.Rows[0]["TxnId"]);
            trTxnID.Visible = true;

        }
       // tdPaymentReceipt.InnerHtml = "";
        ahrefPaymentReceipt.HRef = "CandidatePaymentRecipt.aspx?candidateid=" + Convert.ToString(DtGetUserPaymentDetailsData.Rows[0]["CandidateID"]);
         //tdTxnId.InnerHtml = Convert.ToString(DtGetUserPaymentDetailsData.Rows[0]["TxnId"]);
        //gvCandidatePayment.DataSource = (DtGetUserPaymentDetailsData);
        //gvCandidatePayment.DataBind();

    }

    private DataSet GetCandidateDetailsDataSet(Guid UserID)
    {
        DataSet objDs=null;
        try
        {

            //   objDs = new UserMasterBAL().GetCandidatedetailReg(UserID);

            objDs = new UserMasterBAL().GetCandidateRegByUserId(UserID);

            string strUserRole = CommonUtility.GetCurrentUserRole();
            GetCandidateData(objDs.Tables[0]);
            GetUsersCompany(objDs.Tables[1]);
            string strStatuaID = txtStatusID.Text.Trim();
            int intStatusID = Convert.ToInt32(strStatuaID);

            if (strStatuaID == "1" || strStatuaID == "2" || strStatuaID == "3" || strStatuaID == "23")
            {
                mainMenu.Items.Remove(mainMenu.Items[1]);

            }
            else
            {

                if (strUserRole == "CANM" || strUserRole == "CANB" || strUserRole == "CANR" || strUserRole == "IQKSAD" || strUserRole == "IQKSMG")
                {
                    if (objDs.Tables[2].Rows.Count > 0)
                    {
                        GetUserPaymentDetails(objDs.Tables[2]);
                    }

                }
            }


            //if (strUserRole == "CANM" || strUserRole == "CANB" || strUserRole == "CANR" || strUserRole == "IQKSAD" || strUserRole == "IQKSMG")
            //{
            //    if (strStatuaID=="1" || strStatuaID =="2" || strStatuaID =="3" || strStatuaID =="23")
            //    {
            //        vwTab2.Visible = false;

            //    }
            //    else
            //    {

            //        GetUserPaymentDetails(objDs.Tables[2]);
            //        vwTab2.Visible = true;

            //    }
            //}



        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;
    }

    private void GetUsersCompany(DataTable DtUsersCompanyData)
    {
        gvUser.DataSource = (DtUsersCompanyData);
        gvUser.DataBind();
    }

    protected void btnNext_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/home/CandidateStatus.aspx");
    }

    protected void mainMenu_MenuItemClick(object sender, MenuEventArgs e)
    {

        int intActiveIndex;
        if (e != null)
        {
            mvwCandidateReg.ActiveViewIndex = Int32.Parse(e.Item.Value);
        }

        intActiveIndex = mvwCandidateReg.ActiveViewIndex;



    }





}